<?php

/**
 * This is the model class for table "rapat".
 *
 * The followings are the available columns in table 'rapat':
 * @property integer $id
 * @property string $name
 * @property integer $room_id
 * @property string $user_id
 * @property string $date
 * @property string $time_start
 * @property string $time_end
 * @property integer $participant
 * @property string $message
 * @property string $status
 *
 * The followings are the available model relations:
 * @property AttachmentRapat[] $attachmentRapats
 * @property Ruangan $room
 * @property RejectedMessage $rejectedMessage
 * @property RequestKonsumen $requestKonsumen
 */
class Rapat extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Rapat the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'rapat';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, room_id, user_id, date, time_start, time_end, participant', 'required', 'message'=>'{attribute} tidak boleh kosong'),
			array('room_id, participant', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>255),
			array('status', 'length', 'max'=>8),
			array('message', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, room_id, user_id, date, time_start, time_end, participant, message, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'attachmentRapats' => array(self::HAS_MANY, 'AttachmentRapat', 'rapat_id'),
			'room' => array(self::BELONGS_TO, 'Ruangan', 'room_id'),
			'rejectedMessage' => array(self::HAS_ONE, 'RejectedMessage', 'rapat_id'),
			'requestKonsumen' => array(self::HAS_ONE, 'RequestKonsumen', 'rapat_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Nama Rapat',
			'room_id' => 'Ruangan',
			'user_id' => 'Pemesan',
			'date' => 'Tanggal',
			'time_start' => 'Waktu Mulai',
			'time_end' => 'Waktu Selesai',
			'participant' => 'Jumlah Peserta',
			'message' => 'Pesan',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('room_id',$this->room_id);
		$criteria->compare('user_id',$this->user_id,true);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('time_start',$this->time_start,true);
		$criteria->compare('time_end',$this->time_end,true);
		$criteria->compare('participant',$this->participant);
		$criteria->compare('message',$this->message,true);
		$criteria->compare('status',$this->status,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}